﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LockCrypt.Core.AutoType {
    /// <summary>
    /// Mouse buttons that can be pressed
    /// </summary>
    public enum AutoTypeMouseButton {
        Left = 0x2,
        Right = 0x8,
        Middle = 0x20
    }

    /// <summary>
    /// A click or other mouse event
    /// </summary>
    public class MouseCommand : AutoTypeCommand {
        public AutoTypeMouseButton Button { get; set; }
        public int X { get; set; }
        public int Y { get; set; }

        /// <summary>
        /// Initializes a new empty <see cref="MouseCommand"/>.
        /// </summary>
        public MouseCommand() {
            Button = AutoTypeMouseButton.Left;
            X = -1;
            Y = -1;
        }

        /// <summary>
        /// Initializes a <see cref="MouseCommand"/> from a comma separated values.
        /// </summary>
        /// <param name="action">The action to perform.</param>
        /// <param name="serialized">The serialized.</param>
        public MouseCommand(CommandType action, string serialized) {
            this.Action = action;
            string[] mouseInfo = serialized.Split(','); // expects sometghing like L,897,638 or R,10,20
            Button = mouseInfo[0].ToLowerInvariant() == "l" ? AutoTypeMouseButton.Left : AutoTypeMouseButton.Right;
            X = int.Parse(mouseInfo[1]);
            Y = int.Parse(mouseInfo[2]);
        }

        /// <summary>
        /// Serializes this command.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this command.
        /// </returns>
        public override string ToString() {
            return string.Format("{{{0}:{1},{2},{3}}}\n", Action.ToString(), Button == AutoTypeMouseButton.Left ? 'L' : 'R', X, Y);
        }
    }
}
